package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.config.musicroom.MusicRoomFurnitureConfig;
import com.yanqu.road.entity.config.musicroom.MusicRoomMissionConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class MusicRoomConfigDaoImpl extends TempDao {
    private static String getMusicRoomFurnitureSql = "select * from `t_p_music_room_furniture`";

    public Map<Integer, MusicRoomFurnitureConfig> getMusicRoomFurnitureConfigMap() {
        Map<Integer, MusicRoomFurnitureConfig> configMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(getMusicRoomFurnitureSql);
            rs = call.executeQuery();
            while (rs.next()) {
                MusicRoomFurnitureConfig config = new MusicRoomFurnitureConfig();
                config.setId(rs.getInt("id"));
//                config.setComfort(rs.getString("comfort"));
//                config.setMoodValue(rs.getString("moodValue"));
//                config.setSatiety(rs.getString("satiety"));
//                config.setCostComfort(rs.getString("costComfort"));
//                config.setCostMoodValue(rs.getString("costMoodValue"));
//                config.setCostSatiety(rs.getString("costSatiety"));
                config.setProduceExpBook(rs.getString("produceExpBook"));
                config.setProduceSupportItems(rs.getString("produceSupportItems"));
                config.setProsperity(rs.getInt("prosperity"));
                config.setCost(rs.getString("cost"));
                config.setNeedProsperity(rs.getInt("needProsperity"));
                config.setStandardGrade(rs.getString("standardGrade"));
                config.setGold(rs.getInt("gold"));
                configMap.put(config.getId(), config);
            }
            return configMap;
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
    }

    private static String getMusicRoomMissionConfigSql = "select * from `t_p_music_room_mission`";

    public Map<Integer, MusicRoomMissionConfig> getMusicRoomMissionConfigMap() {
        Map<Integer, MusicRoomMissionConfig> configMap = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(getMusicRoomMissionConfigSql);
            rs = call.executeQuery();
            while (rs.next()) {
                MusicRoomMissionConfig config = new MusicRoomMissionConfig(rs.getInt("id"));
                config.setBattleNum(rs.getInt("battleNum"));
                config.setPassLevel(rs.getInt("passLevel"));
                config.setNeedAttributes(rs.getString("needAttributes"));
                config.setRewards(rs.getString("rewards"));
                configMap.put(config.getId(), config);
            }
            return configMap;
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
    }

}
